'use strict'

define(['jquery', 'bootstrap', 'select2', 'select2.zh', 'datetimepicker', 'datetimepickerCN',
        'shiftform', 'validate', 'validate.en', 'location', 'area'], function($) {
  
  return {
        
    init: function(data) {
      this.data = data;
      this.input();
    },
  
    input: function() {
      
      var that = this;
      
      // bind district picker
      that.initDistrictPicker();
      
      // init page
      $('select[name="userFit.gender"]').select2({
        minimumResultsForSearch: Infinity,
        placeholder : '请选择性别',
        allowClear : true,
        width: '100%'
      });
      
      $('input[name="profile.birthday"]').datetimepicker({
        format: 'yyyy-mm-dd',
        autoclose: true,
        language: 'zh-CN',
        todayBtn: 'linked',
        todayHighlight: true,
        pickerPosition: 'bottom-right',
        minView: 'month'
      })
      
      $('select[name="remark.position"]').select2({
        minimumResultsForSearch: Infinity,
        placeholder : '请选择学员职位',
        allowClear : true,
        width: '100%'
      });
      
      $('select[name="remark.awareChannel"]').select2({
        minimumResultsForSearch: Infinity,
        placeholder : '请选择得知方式',
        allowClear : true,
        width: '100%'
      });
      
      $('select[name="remark.company"]').select2({
        minimumResultsForSearch: Infinity,
        placeholder : '请选择所在公司类型',
        allowClear : true,
        width: '100%'
      });
      
      $('select[name="remark.salary"]').select2({
        minimumResultsForSearch: Infinity,
        placeholder : '请选择年收入范围',
        allowClear : true,
        width: '100%'
      });
      
      $('select[name="profile.marriage"]').select2({
        minimumResultsForSearch: Infinity,
        placeholder : '请选择婚姻状况',
        allowClear : true,
        width: '100%'
      });
      
      $('select[name="profile.haveKids"]').select2({
        minimumResultsForSearch: Infinity,
        placeholder : '请选择是否有子女',
        allowClear : true,
        width: '100%'
      });
      
      $('input[name="profile.hobby"]').select2({
        minimumResultsForSearch: Infinity,
        placeholder: "最多输入两项，输入逗号完成一个输入",
        tokenSeparators: [',', '，'],
        maximumSelectionSize: 2,
        tags: true,
        width: '100%'
      });
      
      $('select[name="remark.visitChannel"]').select2({
        minimumResultsForSearch: Infinity,
        placeholder : '请选择来访渠道',
        allowClear : true,
        width: '100%'
      });
      
      $('select[name="remark.followChannel"]').select2({
        minimumResultsForSearch: Infinity,
        placeholder : '请选择关注健身讯息渠道',
        allowClear : true,
        width: '100%'
      });
      
      $(document).find('form[data-validate="true"]').bt_validate()  //bind validate
      
      var $form = $(document).find("form")                          //bind shiftform
      $form.shiftform({
        beforeSubmit : function(el) {
          $form.trigger("validate.ajax.submit");
          return $.bt_validate.result[$.bt_validate.form_id]
        }
      })
      
    },
    
    initDistrictPicker: function() {
      var that = this;
      showLocation(that.data.province, that.data.region, that.data.district);
    }
    
  }
})
